﻿@{
    ViewBag.Title = "Index";
    ViewBag.First = "个人办公";
    ViewBag.Second = "我的申请";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";
}
<script src="~/Content/laypage-v1.3/laypage/laypage.js"></script>
<script src="~/Content/layer-v2.1/layer/extend/layer.ext.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        loadData(1, 1);
    });
    //数据加载
    function loadData(curr, tag) {
        var url = '@Url.Action("GetPageData")';
        var load = loadTip("数据加载中，请稍候", 16, 0);
        $.get(url, { pageSize: 10, pageIndex: curr }, function (data) {
            $("#listData").find("tr").remove();
            if (tag == 1) {
                initPage(data.PageCount, 1);
                $("#recordCount").html(data.RecordCount);
            }
            var table = document.getElementById("listData");
            $.each(data.Data, function (index, n) {
                var row = table.insertRow(table.rows.length);
                var cbx = row.insertCell(0);
                cbx.innerHTML = (index + 1);
                var start = row.insertCell(1);
                start.innerHTML = n.StartAddress;
                var end = row.insertCell(2);
                end.innerHTML = n.EndAddress;
                var time = row.insertCell(3);
                time.innerHTML = ChangeDateFormat(n.StartTime, 1);
                var count = row.insertCell(4);
                count.innerHTML = n.TotalCount;
                row.insertCell(5).innerHTML = n.BussinessState == true ? "已申诉" : n.StateName;
                row.insertCell(6).innerHTML = ChangeDateFormat(n.ExDate, 1);
                var rm = row.insertCell(7);
                rm.innerHTML = n.Remark;
                var opa = row.insertCell(8);
                var ophtml = "";
                if (n.IsComplaint == false && n.BussinessState == false && n.InstanceState < 6) {
                    ophtml += "<a href='@Url.Action("Comp")?id=" + n.Id + "' class='tablelink'>申诉</a>&nbsp;&nbsp;";
                    ophtml += "<a href='javascript:void(0);' onclick='cancel(" + n.Id + ")' class='tablelink'>取消用车</a>&nbsp;&nbsp;";
                }
                ophtml += "<a href='@Url.Action("UseCarAppeal", "UseCarApplication")?id=" + n.Id + "' class='tablelink'>详情</a>";
                opa.innerHTML = ophtml;
            });
            $('.tablelist tbody tr:odd').addClass('odd');
            $("#currPage").html(curr);
            layer.close(load);
        });
    }
    //初始化分页
    function initPage(pageCount, curr) {
        laypage({
            cont: 'paginList',
            pages: pageCount,
            first: false,
            last: false,
            skip: true,
            curr: curr || 1,
            jump: function (e, first) {
                if (!first) {
                    loadData(e.curr)
                }
            }
        });
    }
    //取消用车
    function cancel(id) {
        layer.confirm("您确定要取消用车吗", function () {
            var url = "@Url.Action("CancelUseApplication")";
            var load = loadTip("正在取消用车，请稍候", 16, 0);
            $.post(url, { id: id}, function (data) {
                if (data > 0) {
                    layer.msg("取消用车成功", { icon: 1, time: 2000, shade: [0.3, '#000'] }, function () {
                        loadData(1, 2);
                    });
                }
                layer.closeAll();
            });
        });
    }
</script>
<div id="content" class="rightinfo">
    <table class="tablelist">
        <thead>
            <tr>
                <th width="40px">编号</th>
                <th width="120">起点</th>
                <th width="120">终点</th>
                <th width="120">用车时间</th>
                <th width="60">人数</th>
                <th width="60">状态</th>
                <th width="120">返程时间</th>
                <th>备注</th>
                <th width="140">操作</th>
            </tr>
        </thead>
        <tbody id="listData"></tbody>
    </table>
    <div class="pagin">
        <div class="message" style="padding-top:5px;">共&nbsp;<i class="blue" id="recordCount"></i>&nbsp;条记录，当前显示第&nbsp;<i class="blue" id="currPage"></i>&nbsp;页</div>
        <ul class="paginList" id="paginList"></ul>
    </div>
</div>
